#include "process.h"
#include <unistd.h>
#include <string.h> 
#define SIZE 101
#define STYLE '='

void FlushProcess(double total, double cur)
{
    if(cur > total) cur = total;

    double rate = cur /total * 100;
    int cnt = (int)rate;
    char ProcessBuff[SIZE];
    memset (ProcessBuff, '\0', sizeof(ProcessBuff));
    int i = 0;
    for(; i < cnt; i++)
    {
        ProcessBuff[i] = STYLE;
    }
    static const char* lable = "-/|\\";
    static int index  = 0;
    printf("[%-100s][%.1lf%%][%c]\r", ProcessBuff, rate, lable[index++]);
    index %= strlen(lable);
    fflush(stdout);
    if(total == cur)
        printf("\n");
}
//void Process()
//{
//    int cnt = 0;
//    char processbuff[SIZE];
//    memset(processbuff, '\0', sizeof(processbuff));
//    while(cnt <= 100)
//    {
//        printf("[%-100s]%d%%\r", processbuff, cnt);
//        fflush(stdout);
//        processbuff[cnt++] = STYLE;
//        usleep(30000);
//    }
//
//    printf("\n");
//}

